package leetcode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class code30 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        int i = Integer.valueOf(scanner.nextLine());
        String[] words = new String[i];
        for (int i1 = 0; i1 < i; i1++) {
            words[i1] = scanner.nextLine();
        }
        List<Integer> substring = findSubstring(s, words);
        for (Integer integer : substring) {
            System.out.println(integer);
        }
    }

    public static List<Integer> findSubstring(String s, String[] words) {
        List<Integer> res = new ArrayList<>();
        //确定 滑动窗口 长度为words的长度
        int left = 0;
        int right = left + words.length * words[0].length() -1;

        while (right <= s.length()-1){
            String window = s.substring(left,right+1);
            HashMap<String,Integer> map = new HashMap<>();
            for (int i = 0; i < words.length; i++) {
                map.put(words[i], map.getOrDefault(words[i], 0) + 1);
            }

            //将这个滑动窗口中拆分为多个长度为word数组
            List<String> result = new ArrayList<>();
            int index = 0;
            for (int i = 0; i <  window.length(); i += words[0].length()) {
                result.add( window.substring(i, Math.min(i + words[0].length(), s.length())));
            }
            //遍历数组，查看是否在map中，
            for (int i = 0; i < result.size(); i++) {
                //在map中
                if (map.containsKey(result.get(i)) && map.get(result.get(i)) > 0){
                    map.put(result.get(i),map.get(result.get(i))-1);
                    index ++;
                    if (index == result.size()){
                        res.add(left);
                        left ++;
                        right = left + words.length * words[0].length() -1;
                    }
                }
                //不在map中，那就不用继续比较了，直接往前滑动一位
                else {
                    left ++;
                    right = left + words.length * words[0].length() -1;
                    break;
                }
            }
        }
        return res;
    }
}
